﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Ebiz
{
    public partial class ErrorPage : System.Web.UI.Page
    {
        public string ErrorCode = "";
        public string ErrDescriptions = "";
        private string[] tmpErrCode;
        protected void Page_Load(object sender, EventArgs e){
            string ErrPrefix = "";
            string ErrCode = "";
            if (!(Session.IsNewSession || Session["ErrCode"] == null)){
                if (!(string.IsNullOrEmpty(Session["ErrCode"].ToString()))){
                    tmpErrCode = Session["ErrCode"].ToString().Split('-');
                    ErrPrefix = tmpErrCode[0];
                    ErrCode = tmpErrCode[1];
                }
            }

            ErrorCode = "(" + ErrPrefix + ErrCode + ")";
            switch (ErrPrefix){
                case "ES":
                    ErrDescriptions = ErrSystem(ErrCode);
                    btnBack.Visible = BtnVisibleES(ErrCode);
                    break;
                case "ED":
                    ErrDescriptions = ErrDatabase(ErrCode);
                    break;
                default:
                    ErrDescriptions = "Internal System Error";
                    break;
            }
        }

        private static string ErrSystem(string ErrorCode){
            string result = "";
            switch (ErrorCode){
                case "100":
                    result = "Insert new data failed";
                    break;
                case "101":
                    result = "Update data failed";
                    break;
                case "102":
                    result = "Delete data failed";
                    break;
                case "104":
                    result = "Sorry, you are not authorized using this system";
                    break;
                case "404":
                    result = "Page not found";
                    break;
                default:
                    result = "Internal System Error";
                    break;
            }
            return result;
        }

        private static string ErrDatabase(string ErrorCode){
            string result = "";

            return result;
        }

        private bool BtnVisibleES(string ErrorCode){
            bool result = false;
            switch (ErrorCode){
                case "104":
                    result = false;
                    break;
                default:
                    result = true;
                    break;
            }
            return result;
        }

    }
}
